# 按照LFS的编译说明进行的总结
# 支持各个阶段选择是否进行执行
# 当执行过程中遇到错误停止执行
set -e # 如果遇到错误，停止执行 

# 参数设置
#     当前编译根目录 
build_root_path="/sdaN"

# 2.5章节 设置LFS环境变量
export LFS=$build_root_path

# 判断sources目录是否存在，不存在则创建
if [ ! -d "$LFS/sources" ]; then
mkdir -v $LFS/sources
chmod -v a+wt $LFS/sources 
cd $LFS/sources
wget http://www.linuxfromscratch.org/lfs/view/stable/wget-list
wget http://www.linuxfromscratch.org/lfs/view/stable/md5sums
fi 

#wget -i wget-list -P $LFS/sources
cd $LFS/sources

if [ ! -f "acl-2.2.52.src.tar.gz" ]; then
wget http://download.savannah.gnu.org/releases/acl/acl-2.2.52.src.tar.gz
fi
if [ ! -f "attr-2.4.47.src.tar.gz" ]; then
wget http://download.savannah.gnu.org/releases/attr/attr-2.4.47.src.tar.gz
fi
if [ ! -f "autoconf-2.69.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/autoconf/autoconf-2.69.tar.xz
fi
if [ ! -f "automake-1.14.1.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/automake/automake-1.14.1.tar.xz
fi
if [ ! -f "bash-4.3.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/bash/bash-4.3.tar.gz
fi
if [ ! -f "bc-1.06.95.tar.bz2" ]; then
wget http://alpha.gnu.org/gnu/bc/bc-1.06.95.tar.bz2
fi
if [ ! -f "binutils-2.24.tar.bz2" ]; then
wget http://mirrors.ustc.edu.cn/gnu/binutils/binutils-2.24.tar.bz2
fi
if [ ! -f "bison-3.0.2.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/bison/bison-3.0.2.tar.xz
fi
if [ ! -f "bzip2-1.0.6.tar.gz" ]; then
wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
fi
if [ ! -f "check-0.9.14.tar.gz" ]; then
wget http://sourceforge.net/projects/check/files/check/0.9.14/check-0.9.14.tar.gz
fi
if [ ! -f "coreutils-8.23.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/coreutils/coreutils-8.23.tar.xz
fi
if [ ! -f "dejagnu-1.5.1.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/dejagnu/dejagnu-1.5.1.tar.gz
fi
if [ ! -f "diffutils-3.3.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/diffutils/diffutils-3.3.tar.xz
fi
if [ ! -f "eudev-1.10.tar.gz" ]; then
wget http://dev.gentoo.org/~blueness/eudev/eudev-1.10.tar.gz
fi
if [ ! -f "eudev-1.10-manpages.tar.bz2" ]; then
wget http://anduin.linuxfromscratch.org/sources/other/eudev-1.10-manpages.tar.bz2
fi
if [ ! -f "e2fsprogs-1.42.12.tar.gz" ]; then
wget http://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v1.42.12/e2fsprogs-1.42.12.tar.gz
fi
if [ ! -f "expat-2.1.0.tar.gz" ]; then
wget http://prdownloads.sourceforge.net/expat/expat-2.1.0.tar.gz
fi
if [ ! -f "expect5.45.tar.gz" ]; then
wget http://prdownloads.sourceforge.net/expect/expect5.45.tar.gz
fi
if [ ! -f "file-5.19.tar.gz" ]; then
wget ftp://ftp.astron.com/pub/file/file-5.19.tar.gz
fi
if [ ! -f "findutils-4.4.2.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/findutils/findutils-4.4.2.tar.gz
fi
if [ ! -f "flex-2.5.39.tar.bz2" ]; then
wget http://prdownloads.sourceforge.net/flex/flex-2.5.39.tar.bz2
fi
if [ ! -f "gawk-4.1.1.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/gawk/gawk-4.1.1.tar.xz
fi
if [ ! -f "gcc-4.9.1.tar.bz2" ]; then
wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.9.1/gcc-4.9.1.tar.bz2
fi
if [ ! -f "gdbm-1.11.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/gdbm/gdbm-1.11.tar.gz
fi
if [ ! -f "gettext-0.19.2.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/gettext/gettext-0.19.2.tar.xz
fi
if [ ! -f "glibc-2.20.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/glibc/glibc-2.20.tar.xz
fi
if [ ! -f "gmp-6.0.0a.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu//gmp/gmp-6.0.0a.tar.xz
fi
if [ ! -f "gperf-3.0.4.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/gperf/gperf-3.0.4.tar.gz
fi
if [ ! -f "grep-2.20.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/grep/grep-2.20.tar.xz
fi
if [ ! -f "groff-1.22.2.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/groff/groff-1.22.2.tar.gz
fi
if [ ! -f "grub-2.00.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/grub/grub-2.00.tar.xz
fi
if [ ! -f "gzip-1.6.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/gzip/gzip-1.6.tar.xz
fi
if [ ! -f "iana-etc-2.30.tar.bz2" ]; then
wget http://anduin.linuxfromscratch.org/sources/LFS/lfs-packages/conglomeration/iana-etc/iana-etc-2.30.tar.bz2
fi
if [ ! -f "inetutils-1.9.2.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/inetutils/inetutils-1.9.2.tar.gz
fi
if [ ! -f "intltool-0.50.2.tar.gz" ]; then
wget http://launchpad.net/intltool/trunk/0.50.2/+download/intltool-0.50.2.tar.gz
fi
if [ ! -f "iproute2-3.16.0.tar.xz" ]; then
wget https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.16.0.tar.xz
fi
if [ ! -f "kbd-2.0.2.tar.gz" ]; then
wget https://www.kernel.org/pub/linux/utils/kbd/kbd-2.0.2.tar.gz
fi
if [ ! -f "kmod-18.tar.xz" ]; then
wget https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-18.tar.xz
fi
if [ ! -f "less-458.tar.gz" ]; then
wget http://www.greenwoodsoftware.com/less/less-458.tar.gz
fi
if [ ! -f "lfs-bootscripts-20140815.tar.bz2" ]; then
wget http://www.linuxfromscratch.org/lfs/downloads/7.6/lfs-bootscripts-20140815.tar.bz2
fi
if [ ! -f "libcap-2.24.tar.xz" ]; then
wget https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.24.tar.xz
fi
if [ ! -f "libpipeline-1.3.0.tar.gz" ]; then
wget http://download.savannah.gnu.org/releases/libpipeline/libpipeline-1.3.0.tar.gz
fi
if [ ! -f "libtool-2.4.2.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/libtool/libtool-2.4.2.tar.gz
fi
if [ ! -f "linux-3.16.2.tar.xz" ]; then
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.16.2.tar.xz
fi
if [ ! -f "m4-1.4.17.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/m4/m4-1.4.17.tar.xz
fi
if [ ! -f "make-4.0.tar.bz2" ]; then
wget http://mirrors.ustc.edu.cn/gnu/make/make-4.0.tar.bz2
fi
if [ ! -f "man-db-2.6.7.1.tar.xz" ]; then
wget http://download.savannah.gnu.org/releases/man-db/man-db-2.6.7.1.tar.xz
fi
if [ ! -f "man-pages-3.72.tar.xz" ]; then
wget https://www.kernel.org/pub/linux/docs/man-pages/man-pages-3.72.tar.xz
fi
if [ ! -f "mpc-1.0.2.tar.gz" ]; then
wget http://www.multiprecision.org/mpc/download/mpc-1.0.2.tar.gz
fi
if [ ! -f "mpfr-3.1.2.tar.xz" ]; then
wget http://www.mpfr.org/mpfr-3.1.2/mpfr-3.1.2.tar.xz
fi
if [ ! -f "ncurses-5.9.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu//ncurses/ncurses-5.9.tar.gz
fi
if [ ! -f "patch-2.7.1.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/patch/patch-2.7.1.tar.xz
fi
if [ ! -f "perl-5.20.0.tar.bz2" ]; then
wget http://www.cpan.org/src/5.0/perl-5.20.0.tar.bz2
fi
if [ ! -f "pkg-config-0.28.tar.gz" ]; then
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
fi
if [ ! -f "procps-ng-3.3.9.tar.xz" ]; then
wget http://sourceforge.net/projects/procps-ng/files/Production/procps-ng-3.3.9.tar.xz
fi
if [ ! -f "psmisc-22.21.tar.gz" ]; then
wget http://downloads.sourceforge.net/project/psmisc/psmisc/psmisc-22.21.tar.gz
fi
if [ ! -f "readline-6.3.tar.gz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/readline/readline-6.3.tar.gz
fi
if [ ! -f "sed-4.2.2.tar.bz2" ]; then
wget http://mirrors.ustc.edu.cn/gnu/sed/sed-4.2.2.tar.bz2
fi
if [ ! -f "shadow-4.2.1.tar.xz" ]; then
wget http://pkg-shadow.alioth.debian.org/releases/shadow-4.2.1.tar.xz
fi
if [ ! -f "sysklogd-1.5.tar.gz" ]; then
wget http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.tar.gz
fi
if [ ! -f "sysvinit-2.88dsf.tar.bz2" ]; then
wget http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf.tar.bz2
fi
if [ ! -f "tar-1.28.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/tar/tar-1.28.tar.xz
fi
if [ ! -f "tcl8.6.2-src.tar.gz" ]; then
wget http://downloads.sourceforge.net/project/tcl/Tcl/8.6.2/tcl8.6.2-src.tar.gz
fi
if [ ! -f "texinfo-5.2.tar.xz" ]; then
wget http://mirrors.ustc.edu.cn/gnu/texinfo/texinfo-5.2.tar.xz
fi
if [ ! -f "tzdata2014g.tar.gz" ]; then
wget http://www.iana.org/time-zones/repository/releases/tzdata2014g.tar.gz
fi
if [ ! -f "udev-lfs-20140408.tar.bz2" ]; then
wget http://anduin.linuxfromscratch.org/sources/other/udev-lfs-20140408.tar.bz2
fi
if [ ! -f "util-linux-2.25.1.tar.xz" ]; then
wget https://www.kernel.org/pub/linux/utils/util-linux/v2.25/util-linux-2.25.1.tar.xz
fi
if [ ! -f "vim-7.4.tar.bz2" ]; then
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
fi
if [ ! -f "XML-Parser-2.42_01.tar.gz" ]; then
wget http://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.42_01.tar.gz
fi
if [ ! -f "xz-5.0.5.tar.xz" ]; then
wget http://tukaani.org/xz/xz-5.0.5.tar.xz
fi
if [ ! -f "zlib-1.2.8.tar.xz" ]; then
wget http://www.zlib.net/zlib-1.2.8.tar.xz
fi
if [ ! -f "bash-4.3-upstream_fixes-3.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/bash-4.3-upstream_fixes-3.patch
fi
if [ ! -f "bc-1.06.95-memory_leak-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/bc-1.06.95-memory_leak-1.patch
fi
if [ ! -f "binutils-2.24-load_gcc_lto_plugin_by_default-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/binutils-2.24-load_gcc_lto_plugin_by_default-1.patch
fi
if [ ! -f "binutils-2.24-lto_testsuite-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/binutils-2.24-lto_testsuite-1.patch
fi
if [ ! -f "bzip2-1.0.6-install_docs-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/bzip2-1.0.6-install_docs-1.patch
fi
if [ ! -f "coreutils-8.23-i18n-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/coreutils-8.23-i18n-1.patch
fi
if [ ! -f "gcc-4.9.1-upstream_fixes-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/gcc-4.9.1-upstream_fixes-1.patch
fi
if [ ! -f "glibc-2.20-fhs-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/glibc-2.20-fhs-1.patch
fi
if [ ! -f "kbd-2.0.2-backspace-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/kbd-2.0.2-backspace-1.patch
fi
if [ ! -f "mpfr-3.1.2-upstream_fixes-2.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/mpfr-3.1.2-upstream_fixes-2.patch
fi
if [ ! -f "readline-6.3-upstream_fixes-2.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/readline-6.3-upstream_fixes-2.patch
fi
if [ ! -f "sysvinit-2.88dsf-consolidated-1.patch" ]; then
wget http://www.linuxfromscratch.org/patches/lfs/7.6/sysvinit-2.88dsf-consolidated-1.patch
fi

pushd $LFS/sources
md5sum -c md5sums
popd



